﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Isuka.Iteration;
using Isuka.Linq;
using Isuka.Text;
using Isuka.Spiritual.Auxiliaries;
using System.Globalization;

namespace Isuka.Spiritual.Appendix
{
    public class DefinedCharRules<A>
        : CharRules<A>
        where A : class
    {

        public static RuleHolder<char, A> IdentifierStart = If(x => char.IsLetter(x) || x == '_');
        public static RuleHolder<char, A> IdentifierPart = If(x => char.IsLetterOrDigit(x) || x == '_');

        public static ValueConvertibleRule<string, char, A> Identifier
            = (IdentifierStart % NoSkipScope(IdentifierPart.ZeroOrMore())).ToConvertible();


        // 16進エスケープ文字
        public static ValueConvertibleRule<int, char, A> HexadecimalEscapeSequence
            = ("\\x" % HexDigits(1, 4)).ToConvertible((string v) => int.Parse(v.Substring(2), NumberStyles.AllowHexSpecifier));

        // 16進エスケープ文字
        public static ValueConvertibleRule<int, char, A> UnicodeEscapeSequence
            = (("\\u" % HexDigits(4, 4)) | ("\\U" % HexDigits(8, 8))).ToConvertible((string v) => int.Parse(v.Substring(2), NumberStyles.AllowHexSpecifier));

        
    }
}
